<?php
require_once '../params.inc';
require_once '../session.inc';
require_once '../utils.inc';
require_once '../shop.inc';


if ($par->exist('del')) 
{
	$keyFields = new DecodedFieldValues($par->get('keys'));
	$optionId = $keyFields->getValueOf('cf_product_options.id');

	ProductOption::del($optionId);
	
	header("Location: " . $par->get('target'));
	exit;
}

$optionId = $par->get('optionId');
$action = $par->get('do');

if ('attributes' == $action) 
{
	$attributes = new ProductOptionAttributes($optionId, true);
	
	foreach ($attributes as $attr) 
	{
		$parName = 'attribute_' . $attr->id();
		if ($par->exist($parName)) {
			$attr->setValue($par->get($parName));
		}
		else {
			$attr->setValue(null);
		}
	}
	
	$option = new ProductOption($optionId);
	$option->setAttributes($attributes);
	
	session::open();
	$target = session::get('cf_orig_target');
	
	header("Location: $target");
	exit;
}

assert(false);
?>